﻿/*************************************************************************************
 * 文 件 名:   HK_MakeGroup
 * 
 * 描    述:   工具全局设置
 * 
 * 版    本：  V1.0
 * 创 建 者：  京产肠饭
 * 创建时间：  2021/8/30
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using System;
using UnityEditor;

public class HK_ToolSetting : EditorWindow
{
    bool isEnableSmartCopy = true;
    bool isEnableMakeGroup = true;
    bool isEnableHierarchyPro = true;
    bool isEnableAutoSwitchToUTF8 = true;

    bool smartCopyState = false;
    bool makeGroupState = false;
    bool hierarchyProState = false;
    bool autoSwitchToUTF8State = false;

    public static event Action<bool> ChangeSmartCopyEvent;
    public static event Action<bool> ChangeMakeGroupEvent;
    public static event Action<bool> ChangeHierarchyEvent;
    public static event Action<bool> ChangeAutoSwitchToUTF8Event;

    [MenuItem("HKTools/Settings...", false, 2000)]
    static void ShowSettingWindow()
    {
        EditorWindow settingWindow = GetWindow<HK_ToolSetting>("HKToolsSetting");
        settingWindow.Show();
    }

    void OnEnable()
    {
        isEnableSmartCopy = EditorPrefs.GetBool("IsEnableSmartCopy", true);
        isEnableMakeGroup = EditorPrefs.GetBool("IsEnableMakeGroup", true);
        isEnableHierarchyPro = EditorPrefs.GetBool("IsEnableHierarchyPro", true);
        isEnableAutoSwitchToUTF8 = EditorPrefs.GetBool("IsAutoSwitchToUTF8", true);

        smartCopyState = isEnableSmartCopy;
        makeGroupState = isEnableMakeGroup;
        hierarchyProState = isEnableHierarchyPro;
        autoSwitchToUTF8State = isEnableAutoSwitchToUTF8;
    }

    void OnGUI()
    {
        EditorGUILayout.Space(5);

        EditorGUILayout.LabelField("全局设置", EditorStyles.boldLabel);

        EditorGUILayout.Space(5);

        isEnableSmartCopy = EditorGUILayout.ToggleLeft("是否启用 Smart Copy", isEnableSmartCopy);

        if (smartCopyState != isEnableSmartCopy)
        {
            ChangeSmartCopyEvent?.Invoke(isEnableSmartCopy);

            smartCopyState = isEnableSmartCopy;

            EditorPrefs.SetBool("IsEnableSmartCopy", isEnableSmartCopy);
        }

        EditorGUILayout.Space(5);

        isEnableMakeGroup = EditorGUILayout.ToggleLeft("是否启用 MakeGroup", isEnableMakeGroup);

        if (makeGroupState != isEnableMakeGroup)
        {
            ChangeMakeGroupEvent?.Invoke(isEnableMakeGroup);

            makeGroupState = isEnableMakeGroup;

            EditorPrefs.SetBool("IsEnableMakeGroup", isEnableMakeGroup);
        }

        EditorGUILayout.Space(5);

        isEnableHierarchyPro = EditorGUILayout.ToggleLeft("是否启用 HierarchyPro", isEnableHierarchyPro);

        if (hierarchyProState != isEnableHierarchyPro)
        {
            ChangeHierarchyEvent?.Invoke(isEnableHierarchyPro);

            hierarchyProState = isEnableHierarchyPro;

            EditorPrefs.SetBool("IsEnableHierarchyPro", isEnableHierarchyPro);
        }

        EditorGUILayout.Space(5);

        isEnableAutoSwitchToUTF8 = EditorGUILayout.ToggleLeft("是否启用 AutoSwitchToUTF8", isEnableAutoSwitchToUTF8);

        if (autoSwitchToUTF8State != isEnableAutoSwitchToUTF8)
        {
            ChangeAutoSwitchToUTF8Event?.Invoke(isEnableAutoSwitchToUTF8);

            autoSwitchToUTF8State = isEnableAutoSwitchToUTF8;

            EditorPrefs.SetBool("IsAutoSwitchToUTF8", isEnableAutoSwitchToUTF8);
        }
    }
}
